import time

from selenium.webdriver.support.ui import WebDriverWait

class Base:
    def __init__(self,driver):
        self.driver = driver
    def open_url(self,url):
        self.driver.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as p:
            out_time = time.strftime('%Y%m%d %H%M%S')
            self.driver.save_screenshot(f'D:\Pycharm_Django\PyCharm\Data_10_12\src\Log\ {out_time}.png')
            print(p)
    def find_elements(self,loc):
        try:
            for i in self.driver.find_elements(*loc):
                return print(i.text)
        except Exception as p:
            print(p)
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def click(self,loc):
        click_loc = self.find_element(loc)
        if click_loc:
            click_loc.click()
    def text(self,loc):
        text_loc = self.find_element(loc)
        if text_loc:
            return text_loc.text
        return ""











